# -*- coding: utf-8 -*-
# @日期 : 2022/1/24 0024
# @作者 : sean
# @版本 : v1.0
# @功能 :

import requests

if __name__ == '__main__':
    print("请选择翻译类型----0：英译汉 1：汉译英")
    trans_type = int(input())
    # 待翻译句子
    sentence = input("输入要翻译的语句：")

    url = 'https://fanyi.baidu.com/v2transapi'

    data = {
        'from':'en',
        'to' :'zh',
        'query': sentence,
        'transtype': 'translang',
        'simple_means_flag': 3,
        'sign': '225682.496291',
        'token': 'a9200f15bec95a9dc736f1caabd07445',
        'domain': 'common'
    }
    if trans_type == 1:
        data = {
            'from': 'zh',
            'to': 'en',
            'query': sentence,
            'transtype': 'translang',
            'simple_means_flag': 3,
            'sign': '262931.57378',
            'token': 'a9200f15bec95a9dc736f1caabd07445',
            'domain': 'common'
        }
    headers={
        'UserAgent' : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36 Edg/97.0.1072.69"
    }


    res = requests.post(url=url,data=data,headers=headers)

    print(res.json())